package com.example.gulimall.order.rabbit.listener;

import com.example.common.config.rabbit.order.OrderTransactionalConfig;
import com.example.common.to.kill.SecKillOrderTo;
import com.example.gulimall.order.service.OrderService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

/**
 * <p>
 *      秒杀订单信息监听
 * </p>
 *
 * @author zyred
 * @since v 0.1
 **/
@Slf4j
@Configuration
@RabbitListener(queues = OrderTransactionalConfig.SEC_KILL_QUEUE)
public class SecKillOrderRabbitListener {

    @Autowired private OrderService orderService;

    @RabbitHandler
    public void secKillOrderHandler (Message message, Channel channel, SecKillOrderTo to) {
        this.orderService.createSecKillOrder (to);
    }

    /**
     * 处理订单信息
     */
    private void orderHandler (SecKillOrderTo to) {
        // 1. 根据商品id扣减库存
        // 2. 生成订单任务
        // 3. 生成订单
    }
}
